package com.example.moblie2030606150cjk0406;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private TextView tvMianTitle;
    private RadioGroup radgupCarType;
    private RadioButton radbtnMainSaloon;
    private RadioButton radbtnMainMvp;
    private RadioButton radbtnMainSuv;
    private RadioGroup radgupMainLine;
    private RadioButton radbtnMainLine1;
    private RadioButton radbtnMainLine2;
    private RadioButton radbtnMainLine3;
    private RadioButton radbtnMainLine4;
    private Button btnMainCreate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        radgupCarType.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        radgupMainLine.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                RadioButton radioButton = findViewById(i);
                Log.i("RadioButton", radioButton.getText().toString());
            }
        });
        btnMainCreate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String msg = "";
                int carID = radgupCarType.getCheckedRadioButtonId();

                if (carID != -1) {
                    msg = ((RadioButton) findViewById(carID)).getText().toString();
                } else {
                    msg = "未选车型";
                }
                int lineId = radgupMainLine.getCheckedRadioButtonId();

                if (lineId!= -1){
                    msg+=","+((RadioButton) findViewById(lineId)).getText().toString();
                }else {
                    msg = "未选生产线";
                }
                Log.i("点击按钮", msg);
            }
        });
    }

    private void initView() {
        tvMianTitle = (TextView) findViewById(R.id.tv_mian_title);
        radgupCarType = (RadioGroup) findViewById(R.id.radgup_car_type);
        radbtnMainSaloon = (RadioButton) findViewById(R.id.radbtn_main_saloon);
        radbtnMainMvp = (RadioButton) findViewById(R.id.radbtn_main_mvp);
        radbtnMainSuv = (RadioButton) findViewById(R.id.radbtn_main_suv);
        radgupMainLine = (RadioGroup) findViewById(R.id.radgup_main_line);
        radbtnMainLine1 = (RadioButton) findViewById(R.id.radbtn_main_line1);
        radbtnMainLine2 = (RadioButton) findViewById(R.id.radbtn_main_line2);
        radbtnMainLine3 = (RadioButton) findViewById(R.id.radbtn_main_line3);
        radbtnMainLine4 = (RadioButton) findViewById(R.id.radbtn_main_line4);
        btnMainCreate = (Button) findViewById(R.id.btn_main_create);

    }
}